﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.Common;
using LGCourt.Logic.BLL;
using LGCourt.Logic.NBL.DBEntities;

namespace lgweb.control.inside.department
{
    public partial class department : System.Web.UI.UserControl
    {
        private string TagIndex = "1";
        private string deptCode = "";
        private string deptID = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {                 
                this.deptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" : Request.QueryString["deptid"].ToString();
                this.TagIndex = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "1" : Request.QueryString["cate"];
                this.deptCode = string.IsNullOrEmpty(Request.QueryString["Code"]) ? "" : Request.QueryString["Code"].ToString();
                GetNewsList();
                SetTagIndex();                
            }
        }

        private void SetTagIndex()
        {
            this.a_dept_name1.HRef = string.Format("/inside/department/notice.aspx?cate=1&deptid={0}&Code={1}", deptID, deptCode);
            this.a_dept_name2.HRef = string.Format("/inside/department/list.aspx?cate=2&deptid={0}&Code={1}", deptID, deptCode);
            this.a_dept_name3.HRef = string.Format("/inside/department/list.aspx?cate=3&deptid={0}&Code={1}", deptID, deptCode);
            this.a_dept_name4.HRef = string.Format("/inside/department/list.aspx?cate=4&deptid={0}&Code={1}", deptID, deptCode);
            this.a_dept_name5.HRef = string.Format("/inside/department/list.aspx?cate=5&deptid={0}&Code={1}", deptID, deptCode);
            this.a_dept_name6.HRef = string.Format("/inside/department/deptinfo.aspx?cate=6&deptid={0}&Code={1}", deptID, deptCode);
            switch (this.TagIndex)
            {                    
                case "1":
                    this.li_dept_name1.Attributes.Add("class", "current");                    
                    break;
                case "2":
                    this.li_dept_name2.Attributes.Add("class", "current");                   
                    break;
                case "3":
                    this.li_dept_name3.Attributes.Add("class", "current");                    
                    break;
                case "4":
                    this.li_dept_name4.Attributes.Add("class", "current");                    
                    break;
                case "5":
                    this.li_dept_name5.Attributes.Add("class", "current");                    
                    break;
                case "6":
                    this.li_dept_name6.Attributes.Add("class", "current");
                    break;
                default:
                    this.li_dept_name1.Attributes.Add("class", "current");                    
                    break;
            }
        }

        //获取资讯类信息列表
        private void GetNewsList()
        {                       
            ColInfo colInfoBLL = new ColInfo();
            DeptClassCondition param = new DeptClassCondition();
            string detpName = "";
            if (deptID == "0")
            {
                DepartmentHandler departmentHandler = new DepartmentHandler();
                Department department = departmentHandler.GetDepartmentInfo(deptCode);
                if (department != null)
                {                    
                    detpName = department.Name;
                }
                //根据名称取部门ID
                param.Source = detpName;
            }
            else
            {
                param.ClassID = int.Parse(deptID);
            }
            param.Name = "部门";
            V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (deptInfo == null)
            {
                deptInfo = new V_DICT_SOURCE();
                deptInfo.ID = 1;
            }
            deptID = deptInfo.ID.ToString();
            detpName = deptInfo.Source;
            aDeptName.InnerHtml = detpName;
            aDeptName.HRef = "/inside/department/index.aspx?Code=" + deptCode;
            //部门信息
            DeptCondition deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            LGFY_Platform_Index deptIndex = colInfoBLL.GetDeptIndexInfo(deptParam);
            if (deptIndex != null)
            {
                this.divDeptFG.InnerHtml = deptIndex.StaffIndex;
            }
            List<IF_DeptClass> deptClassList = colInfoBLL.GetDeptClassList(deptParam);            
            a_dept_name2.InnerText = deptClassList.Count >= 1 ? deptClassList[0].ClassName : "重要文件";
            a_dept_name3.InnerText = deptClassList.Count >= 2 ? deptClassList[1].ClassName : "政治学习";
            a_dept_name4.InnerText = deptClassList.Count >= 3 ? deptClassList[2].ClassName : "部门风采";
            a_dept_name5.InnerText = deptClassList.Count >= 4 ? deptClassList[3].ClassName : "办公助手";
        }
    }
}